package com.ptrsystem.siatd.controllers;

import com.ptrsystem.siatd.beans.UnidadDepInterno;
import com.ptrsystem.siatd.dao.logica.MantenimientoUnidDepartIntLogica;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class UnidDepartInternoController {

    @Autowired
    private MantenimientoUnidDepartIntLogica logica;

    @RequestMapping(value = "registrarUniDepInterno.htm", method = RequestMethod.GET)
    private String registrarUnidDeptoInterno(HttpServletRequest req) {
        req.getSession(true).setAttribute("codUniDepInt", logica.generarCodigoUniDeptInt());
        req.getSession(false).setAttribute("result", "estado de Mantenimiento");
        return "Mantenimiento/NRegUniDepInterno";
    }

    @RequestMapping(value = "registraUniDepInterno.htm", method = RequestMethod.POST)
    private String registraUnidDeptoInterno(UnidadDepInterno uniDepInt, HttpServletRequest req) {
        uniDepInt.setCodUnidDepInter(String.valueOf(logica.generarCodigoUniDeptInt()));
        boolean rs = logica.registraUnidDepartInterno(uniDepInt);
        if (rs) {
            req.getSession(false).setAttribute("result", "registro Exitoso");
            req.getSession(false).setAttribute("codUniDepInt", logica.generarCodigoUniDeptInt());

        } else {
            req.getSession(false).setAttribute("result", "registro Fallido");
        }
        return "Mantenimiento/NRegUniDepInterno";
    }
}
